package tester.Utils;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PubUtil {
    public static String getPrefix(String line) {
        Matcher matcher = Pattern.compile("\\[([^\\]]+)\\]").matcher(line);
        return matcher.find() ? matcher.group(1).trim() : null;
    }
    public static String getSuffix(String line) {
        return getSuffix(line,']');
    }
    /**
     * 使用java.io.File删除文件
     * @param filePath 文件路径
     * @return 删除成功返回true，否则返回false
     */
    public static boolean deleteFile(String filePath) {
        File file = new File(filePath);
        if (file.exists()) {
            return file.delete();
        }
        return false;
    }
    public static String getSuffix(String line,char sign) {
        int closingBracketIndex = line.indexOf(sign);
        if (closingBracketIndex != -1 && closingBracketIndex + 1 < line.length()) {
            String contentAfterBrackets = line.substring(closingBracketIndex + 1);
            return contentAfterBrackets.trim();
        } else {
            return "";
        }
    }
    public static String getPrefix(String line,char sign) {
        int closingBracketIndex = line.indexOf(sign);
        if (closingBracketIndex != -1 && closingBracketIndex + 1 < line.length()) {
            String contentAfterBrackets = line.substring(0, closingBracketIndex);
            return contentAfterBrackets.trim();
        } else {
            return "";
        }
    }
}
